package com.iwayin.web.interceptor;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
/**
 * 异常拦截
 * @author xiaobo.feng<xiaobo.feng@foxmail.com>
 *
 * 2011-8-9
 */
public class ExceptionInterceptor extends AbstractInterceptor {
	/**
	 * 
	 */
	private static final long serialVersionUID = -6947955542779474285L;
	protected final Log LOG = LogFactory.getLog(getClass());
	@Override
	public String intercept(ActionInvocation invocation) {
		try {
			return invocation.invoke();
		} catch (Exception e) {
			String actionName = invocation.getInvocationContext().getName();
			invocation.getStack().setValue("exception", e);
			LOG.error("fail in action"+actionName,e);
			return Action.ERROR;
		}
		
	}

}
